<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>

<div id="div1"></div>
<div id="div2"></div>

<script>
description('This tests ensures that an event listener on an attribute node inside a shadow DOM is properly unregistered when parent element of the attribute is moved to a new document.');

var div1 = document.getElementById('div1');
var div2 = document.getElementById('div2');
var shadowRoot = div2.attachShadow({mode: 'open'});

// Register an event listener on an attribute node.
div1.attributes[0].addEventListener('touchstart', function() { });
if (window.internals)
    shouldBe('internals.touchStartOrMoveEventHandlerCount(document)', '1');

// Move the parent element into a shadow DOM.
shadowRoot.appendChild(div1);

// Move the shadow host into a new document.
var doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html');
doc.adoptNode(div2);

// Make sure the handler was unregistered.
if (window.internals)
    shouldBe('internals.touchStartOrMoveEventHandlerCount(document)', '0');

</script>
